//
//  HornCollectionViewCell.swift
//  HoneyBee
//
//  Created by point on 2018/2/27.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

protocol  HornCollectionViewCellDelegate : class {
    func clickHornCollectionViewCellPlay(index:Int)
    
    func clickHornCollectionViewCellDel(index:Int)
}



class HornCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var buttomView: UIView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var deleteBtn: UIButton!
    @IBOutlet weak var imageView: UIImageView!
    
    fileprivate var playBtn:UIButton =  UIButton(frame: CGRect.zero)
    weak var delegate: HornCollectionViewCellDelegate?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.buttomView.backgroundColor = kColorBGGray
        timeLabel.textColor = kColorBtnNormalColor
        imageView.backgroundColor = UIColor.white
        
        contentView.addSubview(playBtn)
        playBtn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 60, height: 60))
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().inset(-25)
        }
        playBtn.setImage(UIImage(named: "VideoPlay"), for: .normal)
        playBtn.addTarget(self, action: #selector(clickPlay(btn:)), for: .touchUpInside)
        
        
      
    }
    
}
extension HornCollectionViewCell {
    
    @objc func clickPlay(btn:UIButton) {
        delegate?.clickHornCollectionViewCellPlay(index: btn.tag)
    }
    
    @objc func clickDel(btn:UIButton) {
        delegate?.clickHornCollectionViewCellDel(index: btn.tag)
    }
    
}

extension HornCollectionViewCell {
    func  configModel(model:[InstitutionResourceModel] , index:IndexPath) {
        playBtn.tag = index.item
        deleteBtn.tag = index.item
        
        if model[index.item].fileType != 0 {
            imageView.showImageS(model[index.item].path + "?vframe/jpg/offset/1")
            playBtn.isHidden = false
        }else {
            imageView.showImageS(model[index.item].path)
            playBtn.isHidden = true
        }
        timeLabel.text =  String.stringToTimeStamp(stringTime: model[index.item].createTime)
        titleLabel.text = model[index.item].title
        deleteBtn.addTarget(self, action: #selector(clickDel(btn:)), for: .touchUpInside)
        
    }
}
